/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.cs576.HyperLinkVideo.authoringtool;

import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;

/**
 * Holds a hyperlink object, which will have a list of keyframes(dimensions), the linkedvideo(secondary video) name
 * and start frame.
 * 
 * The hyperlink object persists until the very last keyframe. In the player, whenever a user clicks within
 * the hyperlink's area, it will display the linkedvideo starting from the startframe.
 * @author Ludo
 */
public class Hyperlink {
    private int id;//2-digit unique int
    private int listIndex;
    private String name;//name of hyperlink
    private int countOfKeyFrames; //not number of keyframes, keeps count of how many have been created. To get unique id
    
    private String linkedVideoName; //name of linkedvideo(secondaryvideo)
    private int linkedVideo; //id of the linkedvideo
    private int linkedVideoStartFrame; //frame to start displaying the linked video
    
    private List<KeyFrame> keyFrames; //holds all keyframes of hyperlink
    private DefaultListModel keyframeModel; //holds model(the gui list) of keyframes
    
    public Hyperlink(int id, int listIndex){
        this.id = id;
        this.listIndex = listIndex;
        name = "Hyperlink"+id;
        countOfKeyFrames = 0;
        linkedVideoName = "None";
        linkedVideo = -1;
        linkedVideoStartFrame = -1;
        keyFrames = new ArrayList<KeyFrame>();
    }
    
    public void setlistIndex(int ind){
        listIndex = ind;
    }
    
    public int getListIndex(){
        return listIndex;
    }
    
    public void setName(String name){
        this.name = name;
    }
    
    public String getName(){
        return name;
    }
    
    /**
     * sets the current tracking area dimensions to a new keyframe object, which
     * is added in sorted order to the list of keyframes. Returns index which it was added to.
     */
    public int addKeyFrame(KeyFrame keyframe){
        countOfKeyFrames++;
        //adding to sorted order
        for(int i = 0 ; i < keyFrames.size(); i++){
            if(keyframe.getFrame() < keyFrames.get(i).getFrame()){
                //first instance where the keyframe we wish to add has a lower frame number than current frame
                //add to this index
                keyFrames.add(i, keyframe);
                return i;
                
            }
        }
        //if greater than all keyframes, add to the end.
        keyFrames.add(keyframe);
        return keyFrames.size()-1;
        
    }
    
    /**
     * Connects the linkvideo with the primaryVideo.
     * 
     * @param name name of the linkVideo
     * @param id id(position) of linkVideo
     * @param startFrame current displayed frame of linkVideo used as startFrame.
     */
    public void setLinkVideo(String name, int id, int startFrame){
        linkedVideo = id;
        linkedVideoName = name;
        linkedVideoStartFrame = startFrame;
    }
    
    public int getID(){
        return id;
    }
    public String getLinkVideoName(){
        return linkedVideoName;
    }
    
    public int getLinkVideoId(){
        return linkedVideo;
    }
    
    public int getLinkVideoStartFrame(){
        return linkedVideoStartFrame;
    }
    
    public List<KeyFrame> getKeyFrames(){
        return keyFrames;
    }
    
    public DefaultListModel getKeyFrameModel(){
        return keyframeModel;
    }
    
    public void setKeyFrameModel(DefaultListModel keyframeModel){
        this.keyframeModel = keyframeModel;
    }
    
}
